package com.example.gw_back_end.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gw_back_end.domain.entities.GameDownloadLink;
import com.example.gw_back_end.mapper.GameDownloadLinkMapper;
import com.example.gw_back_end.service.GameDownloadLinkService;
import org.springframework.stereotype.Service;

@Service
public class GameDownloadLinkServiceImpl extends ServiceImpl<GameDownloadLinkMapper, GameDownloadLink> implements GameDownloadLinkService {

    private final GameDownloadLinkMapper gameDownloadLinkMapper;
    public GameDownloadLinkServiceImpl(GameDownloadLinkMapper gameDownloadLinkMapper) {
        this.gameDownloadLinkMapper = gameDownloadLinkMapper;
    }

    // 新增游戏的下载地址
    @Override
    public boolean addGameDownloadLink(GameDownloadLink gameDownloadLink) {
        return gameDownloadLinkMapper.insert(gameDownloadLink) > 0;
    }

    // 获取游戏的下载地址
    @Override
    public String getGameDownloadLink(String gameId) {
        LambdaQueryWrapper<GameDownloadLink> queryWrapper = new LambdaQueryWrapper<GameDownloadLink>();
        queryWrapper.eq(GameDownloadLink::getGameId, gameId);
        GameDownloadLink gameDownloadLink = gameDownloadLinkMapper.selectById(gameId);
        if(gameDownloadLink != null) {
            return gameDownloadLink.getGameUrl();
        } else {
            return null;
        }
    }

    // 更改游戏的西在地址
    @Override
    public boolean updateGameDownloadLink(GameDownloadLink gameDownloadLink) {
        return gameDownloadLinkMapper.updateById(gameDownloadLink) > 0;
    }
}
